<?php
/*
 短息通知类
*/

class AliyunSMSHelper{
	private $cfg;
	function __construct($youraccesskeyid,$youraccesskeysecret){
		$this->cfg = [
			'yourAccessKeyId' => $youraccesskeyid,
			'yourAccessKeySecret' => $youraccesskeysecret,
		];
	}

	//发送
	public function send($phone,$sign,$templete_code,$param){
		Vendor('aliyunsms.sms');
		
		//短信模板参数
		$param_t = [
			'code' => '5614'
		];
		
		$response = null;
		try{
			$hp = new \AliyunSMS($this->cfg['yourAccessKeyId'],$this->cfg['yourAccessKeySecret']);
			$response = $hp->sendSms($phone,$sign,$templete_code,$param);
		}catch(Exception $e){
			__log($e->getMessage(),'aliyunsms');
		}
		if(empty($response)){
			return false;
		}
		$tmp = json_decode(json_encode($response),true);
		if(empty($tmp) || $tmp['Code'] != 'OK'){
			__log($tmp,'aliyunsms');
			return false;
		}
		return true;
	}


	
}